package gui;

import gui.utils.Window;
import gui.win.about.About;
import gui.win.parameters.Parameters;
import gui.win.runassembly.RunAssembly;
import java.awt.event.*;
import javax.swing.*;

/*Author: John Archer, Contact: john.archer.jpa@gmail.com*/
public class Menu extends JMenuBar implements ActionListener{
    private JMenuItem parameters;
    private JMenuItem runpipeline;
    private JMenuItem about;
    private VTL1 segL1;
    public Menu(VTL1 segL1){
        this.segL1 = segL1;

        JMenu main = new JMenu("Start");
        addJMenuItem(runpipeline = new JMenuItem("Run Assembly"), main);
        //addJMenuItem(runpipeline = new JMenuItem("Stop Assembly"), main);
        this.add(main);

        //JMenu parametersMenu = new JMenu("Advanced");
        //addJMenuItem(parameters = new JMenuItem("Parameters"), parametersMenu);
        //this.add(parametersMenu);

        JMenu aboutMenu = new JMenu("About");
        addJMenuItem(about = new JMenuItem("About"), aboutMenu);
        this.add(aboutMenu);
    }

    private void addJMenuItem(JMenuItem menuItem, JMenu menuToAddTo){       
        menuItem.addActionListener(this);
        menuToAddTo.add(menuItem);
    }

    //also used for the treepopup - not here
    public static Window curJFrame;
    public void actionPerformed(ActionEvent evt){
        Object source = evt.getSource(); 
        try{
            if(source == runpipeline){
                if(curJFrame!=null){curJFrame.dispose();}
                curJFrame = new RunAssembly(segL1);
            }
            else if(source == parameters){
                if(curJFrame!=null){curJFrame.dispose();}
                curJFrame = new Parameters(segL1);
            }
            else if(source == about){
                if(curJFrame!=null){curJFrame.dispose();}
                curJFrame = new About(segL1);
            }
        }
        catch(Exception e){}
    }

    public void updateJWinLocs(int x, int y){
        if(curJFrame!=null){curJFrame.updateJWinLocs(x, y);}
    }
}